{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入要查询的英雄（英文，可只输入开头）：spider\n",
      "搜索中...\n",
      "1010727 Spider-dok\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/b/40/image_not_available/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1009157 Spider-Girl (Anya Corazon)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/a/10/528d369de3e4f/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1009609 Spider-Girl (May Parker)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/1/70/4c003adccbe4f/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1011347 Spider-Ham (Larval Earth)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/b/40/image_not_available/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1009610 Spider-Man\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/3/50/526548a343e4b/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1011054 Spider-Man (1602)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/e/03/5317713c9e746/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1014873 Spider-Man (2099)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/8/c0/520d1ad3e543f/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1016452 Spider-Man (Ai Apaec)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/c/60/4fce7a4d900f4/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1014858 Spider-Man (Ben Reilly)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/9/c0/5317717bed6fe/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1012200 Spider-Man (House of M)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/3/60/5317718f0a2e7/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1017332 Spider-Man (LEGO Marvel Super Heroes)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/5/03/5239c4d095611/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1011114 Spider-Man (Marvel Zombies)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/3/00/531772716d0ac/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1017305 Spider-Man (Marvel: Avengers Alliance)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/9/03/5239b59f49020/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1016181 Spider-Man (Miles Morales)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/f/50/537bcfa1eed73/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1012295 Spider-Man (Noir)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/6/40/531771a14fcf6/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1011377 Spider-Man (Takuya Yamashiro)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/f/50/4be86ad8ada17/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1011010 Spider-Man (Ultimate)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/3/50/531771b4e8c60/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1010795 Spider-Woman (Charlotte Witter)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/c/60/531771afe4ffa/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1009608 Spider-Woman (Jessica Drew)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/b/50/5265479097743/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1010794 Spider-Woman (Mattie Franklin)\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/2/30/531771c2ab020/portrait_small.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "请输入要查询的英雄ID：1011114\n",
      "搜索中...\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<a href=\"http://marvel.com/comics/characters/1011114/spider-man_marvel_zombies?utm_campaign=apiRef&utm_source=25b558c56c28ea8839370f72250e7c31\" target=\"_blank\">Spider-Man (Marvel Zombies)</a>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Zombie Spider-Man ate his own wife and aunt, the only two people left in the world who truly loved him.\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/3/00/531772716d0ac/detail.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "搜索中...\n",
      "3 本相关漫画\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<a href=\"http://marvel.com/comics/issue/22259/amazing_spider-man_1999_573_zombie_variant_1_for_10/zombie_variant_1_for_10?utm_campaign=apiRef&utm_source=25b558c56c28ea8839370f72250e7c31\" target=\"_blank\">Amazing Spider-Man (1999) #573 (ZOMBIE VARIANT (1 FOR 10))</a>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "22259 $0.00\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/6/00/4bb63ab533682/portrait_xlarge.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<a href=\"http://marvel.com/comics/collection/4812/marvel_zombies_hardcover?utm_campaign=apiRef&utm_source=25b558c56c28ea8839370f72250e7c31\" target=\"_blank\">Marvel Zombies (Hardcover)</a>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "4812 $19.99\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/9/40/4bc5cdf085362/portrait_xlarge.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "data": {
      "text/html": [
       "<a href=\"http://marvel.com/comics/issue/3220/marvel_zombies_2005_1?utm_campaign=apiRef&utm_source=25b558c56c28ea8839370f72250e7c31\" target=\"_blank\">Marvel Zombies (2005) #1</a>"
      ],
      "text/plain": [
       "<IPython.core.display.HTML object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "3220 $1.99\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<img src=\"http://i.annihil.us/u/prod/marvel/i/mg/9/00/5ae32391b6e0e/portrait_xlarge.jpg\"/>"
      ],
      "text/plain": [
       "<IPython.core.display.Image object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import marvel\n",
    "from IPython.display import Image, HTML, display\n",
    "PUBLIC_KEY = '25b558c56c28ea8839370f72250e7c31'\n",
    "PRIVATE_KEY = '0929fdf08c3134b73388825d209cc712b4657eda'\n",
    "m = marvel.Marvel(PUBLIC_KEY, PRIVATE_KEY)\n",
    "\n",
    "\n",
    "# In[96]:\n",
    "\n",
    "\n",
    "# 模糊搜索英雄（名字开头）\n",
    "characters = m.characters\n",
    "# all_characters = characters.all()\n",
    "name = input('请输入要查询的英雄（英文，可只输入开头）：')\n",
    "print('搜索中...')\n",
    "all_characters = characters.all(nameStartsWith=name)\n",
    "for c in all_characters['data']['results']:\n",
    "    print(c['id'], c['name'])\n",
    "    pic = c['thumbnail']\n",
    "    display(Image(url=pic['path']+'/portrait_small.'+pic['extension']))\n",
    "\n",
    "\n",
    "# In[97]:\n",
    "\n",
    "\n",
    "hid = input('请输入要查询的英雄ID：')\n",
    "print('搜索中...')\n",
    "character = characters.get(hid)\n",
    "# 英雄信息\n",
    "for c in character['data']['results']:\n",
    "    display(HTML('<a href=\"'+c['urls'][0]['url']+'\" target=\"_blank\">'+c['name']+'</a>'))\n",
    "    print(c['description'])\n",
    "    pic = c['thumbnail']\n",
    "    display(Image(url=pic['path']+'/detail.'+pic['extension']))\n",
    "print('搜索中...')\n",
    "# 漫画信息\n",
    "comics = characters.comics(hid)\n",
    "print(comics['data']['total'], '本相关漫画')\n",
    "for c in comics['data']['results']:\n",
    "    display(HTML('<a href=\"'+c['urls'][0]['url']+'\" target=\"_blank\">'+c['title']+'</a>'))\n",
    "    print(c['id'], '$%.2f'%c['prices'][-1]['price'])\n",
    "    pic = c['thumbnail']\n",
    "    display(Image(url=pic['path']+'/portrait_xlarge.'+pic['extension']))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.5.2"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
